import { combineEpics, Epic } from "redux-observable";

import { of } from "rxjs";
import { switchMap } from "rxjs/operators";

import { State } from "./reducer";
import {
  ActionGetPostsAsync,
  Actions,
  ActionSetCategoryList,
  ActionSetPosts,
  ActTypes
} from "./action";

const getCategoryListEpic = action$ =>
  action$.ofType(ActTypes.GetCategoryListAsync).pipe(
    switchMap(() => {
      // todo 发起请求获取 data
      const data = [];
      return of({ ...new ActionSetCategoryList(data) });
    })
  );

/*const getPostsEpic = action$ =>
  action$.ofType(ActTypes.GetPostsAsync).pipe(
    switchMap(({ payload }) => {
      return of({ ...new ActionSetPosts({ a: [] }) });
    })
  );*/

export const epic = combineEpics(getCategoryListEpic);
